<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function ajax1() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve("data-111")
                }, 1000)
            })
        }
        function ajax2() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve("data-222")
                }, 1000)
            })
        }
        //可以通过try..catch的方式来进行后续操作，也可通过.then.catch进行后续操作
        async function test() {
            try {
                let res1 = await ajax1()
                console.log(res1) //会等待resolve()执行完才继续执行
                let res2 = await ajax2(res1)
                console.log(res2)
                //渲染页面
                console.log("渲染页面")
            } catch (error) {
                //处理错误
                console.log("err", error)
            }
        }
        test()
    </script>
</body>

</html>